#ifndef _WX_SOUND_H_
#define _WX_SOUND_H_

#include "wx/defs.h"
#include "wx/object.h"

class wxSoundBackend;
class wxSound;
class wxDynamicLibrary;

class wxSoundData {
  public:
    wxSoundData() : m_refCnt( 1 ) {}
    void IncRef();
    void DecRef();
    unsigned m_channels;       // num of channels (mono:1, stereo:2)
    unsigned m_samplingRate;
    unsigned m_bitsPerSample;  // if 8, then m_data contains unsigned 8bit
    unsigned m_samples;        // length in samples:
    size_t   m_dataBytes;
    wxUint8 *m_data;           // m_dataBytes bytes of data
  private:
    ~wxSoundData();
    unsigned m_refCnt;
    wxUint8 *m_dataWithHeader; // ditto, but prefixed with .wav header
    friend class wxSound;
};

class wxSound : public wxSoundBase {
  public:
    wxSound();
    wxSound( const wxString& fileName, bool isResource = false );
    wxSound( int size, const wxByte* data );
    virtual ~wxSound();
    bool Create( const wxString& fileName, bool isResource = false );
    bool Create( int size, const wxByte* data );
    bool IsOk() const { return m_data != NULL; }
    static void Stop();
    static bool IsPlaying();
    static void UnloadBackend();
  protected:
    bool DoPlay( unsigned flags ) const;
    static void EnsureBackend();
    void Free();
    bool LoadWAV( const wxUint8 *data, size_t length, bool copyData );
    static wxSoundBackend *ms_backend;
  private:
    wxSoundData *m_data;
};

struct wxSoundPlaybackStatus {
  bool m_playing;
  bool m_stopRequested;
};

class wxSoundBackend {
  public:
    virtual ~wxSoundBackend() {}
    virtual wxString GetName() const = 0;
    virtual int GetPriority() const = 0;
    virtual bool IsAvailable() const = 0;
    virtual bool HasNativeAsyncPlayback() const = 0;
    virtual bool Play( wxSoundData *data, unsigned flags,volatile wxSoundPlaybackStatus *status ) = 0;
    virtual void Stop() = 0;
    virtual bool IsPlaying() const = 0;
};

#endif
